<?php

/**
 * ReservasPersonas form.
 *
 * @package    begurholidays
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class ReservasPersonasRegistroForm extends BaseReservasPersonasForm
{
  public function configure()
  {
	unset($this['created_at'], $this['updated_at']);
	
	$this->widgetSchema->setNameFormat('reservaspersonasregistro[%s]');
	$sexoreserva = array('' =>'', 'M' =>sfContext::getInstance()->getI18N()->__('mujer', null, 'forms'), 'H' => sfContext::getInstance()->getI18N()->__('hombre', null, 'forms'));
	$this->widgetSchema['sexoreserva'] = new sfWidgetFormSelect(array('choices' => $sexoreserva));
	
	
	
	if(sfContext::getInstance()->getUser()->getLangCulture()=='ca'){
		$this->setWidget('paisreserva', new sfWidgetFormI18nChoiceCountry(array('culture' => 'ca', 'countries' => $arrOnlyCountries, 'default' => 'ES')));
	}
	else{
		$this->setWidget('paisreserva', new sfWidgetFormI18nChoiceCountry(array('culture' => sfContext::getInstance()->getUser()->getLangCulture(), 'countries' => $arrOnlyCountries, 'default' => strtoupper(sfContext::getInstance()->getUser()->getLangCulture()))));
	}
	//Eliminamos las zonas (Europa Oriental, America...) del listado de paises del widget
	$cultureInfo = new sfCultureInfo(sfContext::getInstance()->getUser()->getCulture());
	$countries = $cultureInfo->getCountries();
	foreach($countries as $valueKey => $value){
		if(is_numeric($valueKey)){
			unset($countries[$valueKey]);
		}
	}
	$this->widgetSchema['paisreserva']->setOption('choices', $countries);
	
	$tipodocumentoreserva = array('' =>'', 'D' =>sfContext::getInstance()->getI18N()->__('dni', null, 'forms'), 'P' => sfContext::getInstance()->getI18N()->__('pasaporte', null, 'forms'), 'C' => sfContext::getInstance()->getI18N()->__('carnetconducir', null, 'forms'), 'I' => sfContext::getInstance()->getI18N()->__('cartaidentidad', null, 'forms'), 'N' => sfContext::getInstance()->getI18N()->__('permisoresidenciaespanol', null, 'forms'), 'X' => sfContext::getInstance()->getI18N()->__('permisoresidenciapaisUE', null, 'forms'));
	$this->widgetSchema['tipodocumentoreserva'] = new sfWidgetFormSelect(array('choices' => $tipodocumentoreserva));
	
	$yearsBirth = range(date("Y"), date("Y")-110);
	$this->widgetSchema['fechanacreserva'] = new sfWidgetFormI18nDate(array('years' => array_combine($yearsBirth, $yearsBirth),'culture'=> sfContext::getInstance()->getUser()->getLangCulture(), 'month_format' => 'short_name',
));
	
	$this->widgetSchema->setLabel('sexoreserva', sfContext::getInstance()->getI18N()->__('sexoreserva', null, 'forms'));
	$this->widgetSchema->setLabel('nombrereserva', sfContext::getInstance()->getI18N()->__('nombrereserva', null, 'forms'));
	$this->widgetSchema->setLabel('apellidosreserva', sfContext::getInstance()->getI18N()->__('apellidosreserva', null, 'forms'));
	$this->widgetSchema->setLabel('fechanacreserva', sfContext::getInstance()->getI18N()->__('fechanacreserva', null, 'forms'));
	$this->widgetSchema->setLabel('paisreserva', sfContext::getInstance()->getI18N()->__('paisreserva', null, 'forms'));
	$this->widgetSchema->setLabel('tipodocumentoreserva', sfContext::getInstance()->getI18N()->__('tipodocumentoreserva', null, 'forms'));
	$this->widgetSchema->setLabel('dnipasaportereserva', sfContext::getInstance()->getI18N()->__('dnipasaportereserva', null, 'forms'));
	
	//$this->setWidget('fechanacreserva', new sfWidgetFormJQueryDate(array('image'=> '/images/calendar.png', 'culture'=>'es', 'config' => '{minDate: -1, maxDate: "+1M +1D"}', 'date_widget' => new sfWidgetFormDate(array('format' => '%day% %month% %year%')))));
	if($this->getObject()->isNew()){
	$this->setValidators(array(
			'nombrereserva'       => new sfValidatorString(array(), array('max_length' => 255, 'required' => sfContext::getInstance()->getI18N()->__('errorNombrereserva', null, 'forms'))),
			'apellidosreserva'       => new sfValidatorString(array(), array('max_length' => 255, 'required' => sfContext::getInstance()->getI18N()->__('errorApellidosreserva', null, 'forms'))),
			'sexoreserva'       => new sfValidatorString(array(), array('max_length' => 1, 'required' => sfContext::getInstance()->getI18N()->__('errorSexoreserva', null, 'forms'))),
			'fechanacreserva'       => new sfValidatorDate(array(), array('required' => sfContext::getInstance()->getI18N()->__('errorFechanacreserva', null, 'forms'), 'invalid' => sfContext::getInstance()->getI18N()->__('fechaNacimientoNoValida', null, 'forms'))),
			'paisreserva'    => new sfValidatorString(array(), array('max_length' => 100, 'required' => sfContext::getInstance()->getI18N()->__('requiredCountry', null, 'forms'))),
			'tipodocumentoreserva'       => new sfValidatorString(array(), array('max_length' => 1, 'required' => sfContext::getInstance()->getI18N()->__('errorTipodocumentoreserva', null, 'forms'))),
			'dnipasaportereserva'       => new sfValidatorString(array(), array('max_length' => 100, 'required' => sfContext::getInstance()->getI18N()->__('errorDnipasaportereserva', null, 'forms'))),
			'reserva_id'       => new sfValidatorString(array(), array('required' => true)),
	));
	}
	else{
		$this->setValidators(array(
				'nombrereserva'       => new sfValidatorString(array(), array('max_length' => 255, 'required' => sfContext::getInstance()->getI18N()->__('errorNombrereserva', null, 'forms'))),
				'apellidosreserva'       => new sfValidatorString(array(), array('max_length' => 255, 'required' => sfContext::getInstance()->getI18N()->__('errorApellidosreserva', null, 'forms'))),
				'sexoreserva'       => new sfValidatorString(array(), array('max_length' => 1, 'required' => sfContext::getInstance()->getI18N()->__('errorSexoreserva', null, 'forms'))),
				'fechanacreserva'       => new sfValidatorDate(array(), array('required' => sfContext::getInstance()->getI18N()->__('errorFechanacreserva', null, 'forms'), 'invalid' => sfContext::getInstance()->getI18N()->__('fechaNacimientoNoValida', null, 'forms'))),
				'paisreserva'    => new sfValidatorString(array(), array('max_length' => 100, 'required' => sfContext::getInstance()->getI18N()->__('requiredCountry', null, 'forms'))),
				'tipodocumentoreserva'       => new sfValidatorString(array(), array('max_length' => 1, 'required' => sfContext::getInstance()->getI18N()->__('errorTipodocumentoreserva', null, 'forms'))),
				'dnipasaportereserva'       => new sfValidatorString(array(), array('max_length' => 100, 'required' => sfContext::getInstance()->getI18N()->__('errorDnipasaportereserva', null, 'forms'))),
		));
	}
	$this->validatorSchema->setOption('allow_extra_fields', true);
  }
  
}
